package com.fog.student.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fog.student.common.Base;
import com.fog.student.entity.Class;
import com.fog.student.entity.Student;
import com.fog.student.service.ClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/class")
public class ClassController {
    @Resource
    private ClassService classService;
    @GetMapping("/page")
    public Base page(Integer page, Integer pageSize, String name){
        Page<Class> pageInfo = new Page<>(page, pageSize);
        QueryWrapper<Class> classQueryWrapper = new QueryWrapper<>();
        classQueryWrapper.orderByDesc("name");
        if(name !=null){
            classQueryWrapper.like("info", name);
        }
        classService.page(pageInfo, classQueryWrapper);
        return Base.success(pageInfo);
    }
    @GetMapping("/{id}")
    public Base getEmployeeById(@PathVariable Long id){
        Class aClass = classService.getById(id);
        return Base.success(aClass);
    }
    @PutMapping
    public Base updateClass(@RequestBody Class classes){
        classService.saveOrUpdate(classes);
        return Base.success("更新班级成功!");
    }


}
